#!/usr/bin/env python

"""
	A simple IRC Bot, that logs conversation in an IRC Channel

	(C) 2008, Pranav Prakash

	Email: pranny@gmail.com


    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""


"""
This module parses any and all messages that are recieved by the bot from the 
freenode server. It also, invokes various functions that are called, depending
on specific activity
"""

import re

class Parser(object):
	def parse(self, rawServerMessage):
		"""
		The text to be parsed is a message from the server,
		so it has fixed format, which could be retrieved from
		http://www.irchelp.org/irchelp/rfc/chapter4.html
		"""
		#print rawServerMessage
		self.rawText = re.split(':', rawServerMessage)
		self.crudeDetails = self.rawText[1]
		self.message = self.rawText[2]
		self.Details = re.split(" ", self.rawText[1])
		self.messageType = self.Details[1]
		self.messageTo = self.Details[2]
		self.senderNick = re.split("!", self.Details[0])[0]
	
	def messageInfo(self):
		 return (self.senderNick, self.messageTo, self.messageType, self.message)
		 
	def getSender(self):
		return self.senderNick
	
	def getMessageTo(self):
		return self.messageTo
	
	def getMessageType(self):
		return self.messageType
		
	def getMessage(self):
		return self.message
		
		 
	
if __name__ == '__main__':
	p = Parser()
	t = ":pranny!n=pranny@123.201.38.191 PRIVMSG piku_b02 :EXIT"
	p.parse(t)
	print p.messageInfo()
	print p.getSender()
	print p.getMessage()

